﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;

public partial class Admin_DevMan_List : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Response.Write("<table class='layui-table' width='50%'><thead><tr><th><div class='layui-unselect header layui-form-checkbox' lay-skin='primary'><i class='layui-icon'>&#xe605;</i></div></th><th>设备编号</th><th>设备名称</th><th>所属单位</th><th>放置地点</th><th>设备状态</th><th>购买日期</th><th>负责人</th><th>操作</th></tr></thead>");

        string pronum = "";
        pronum = Request.QueryString["num"].ToString();
       // Response.Write(pronum);
        string tabelall = "<table class='layui-table' width='80%'id='table'><thead><th>设备编号</th><th>设备名称</th><th>所属单位</th><th>放置地点</th><th>设备状态</th><th>购买日期</th><th>负责人</th><th>操作</th></tr></thead>";
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringProManage"].ConnectionString;
        try
        {
            conn.Open();

            //删除记录
            SqlCommand cmddel = new SqlCommand();
            string SQLdel = "update Products set flag=0 where (pro_num=@pro_num)";
            cmddel.Connection = conn;
            cmddel.CommandText = SQLdel;
            cmddel.CommandType = CommandType.Text;
            //提交参数 SQL 语句中必须要有@参数
            SqlParameter ppro_num = new SqlParameter("@pro_num", SqlDbType.NVarChar, 10);
            ppro_num.Value = pronum;
            cmddel.Parameters.Add(ppro_num);
            cmddel.ExecuteNonQuery();

            SqlCommand cmd = new SqlCommand();
            string SQL = "select pro_num,pro_name,pro_danwei,pro_location,condition,buydate,auditor from Products where flag=1";
            cmd.Connection = conn;
            cmd.CommandText = SQL;
            cmd.CommandType = CommandType.Text;
            //提交参数 SQL 语句中必须要有@参数
            //SqlParameter ppro_num = new SqlParameter("@pro_num", SqlDbType.NVarChar, 10);
            //ppro_num.Value = keyword;
            //cmd.Parameters.Add(ppro_num);
            //int flag = 0;            //控制表头仅显示一次
            int k = 0;
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                int fieldcount = reader.FieldCount;      //取字段总数
                if (!reader.HasRows)            //有数据  ---行
                {
                    Label1.Text = "<table class='layui-table' style='width: 70%; margin-left:15% '><tr><td>没有数据</td></tr>";
                }
                else
                {
                    string trd = "<tbody>";                     //存储数据
                    while (reader.Read())               //当有数据可读时
                    {
                       /* trd += "<tr><td><div class='layui-unselect header layui-form-checkbox' lay-skin='primary'><i class='layui-icon'>&#xe605;</i></div></td>";  */       //数据行开始，行以tr起
                        trd += "<tr>";
                        for (int i = 0; i < fieldcount; i++)
                        {   //每一列的内容
                            trd += "<td>" + reader[i].ToString() + "</td>";
                        }
                        /*  trd += "<td><a href='Admin_DevMan_Details.aspx?id="+reader[0].ToString()+"'>点击查看</a></td></tr>";  */           //行结束
                        //trd += "<td><a title = '查看详细信息' href = 'Admin_DevMan_Details.aspx?id=" + reader[0].ToString() + "'><i class='layui-icon'>&#xe60b;</i></a>&nbsp;&nbsp;&nbsp;<input type='button' name='getTableContent' value='删除' onclick='getTableContent(this)'></td></tr>";
                        //trd += "<td><a title = '查看详细信息' href = 'Admin_DevMan_Details.aspx?id=" + reader[0].ToString() + "'><i class='layui-icon'>&#xe60b;</i></a>&nbsp;&nbsp;&nbsp;<a title='删除' name='getTableContent' onclick='getTableContent(this)'><i class='layui-icon'>&#xe640;</i></td></tr>";
                        trd += "<td><a title = '查看详细信息' href = 'Admin_DevMan_Details.aspx?id=" + reader[0].ToString() + "'><i class='layui-icon'>&#xe60b;</i></a>&nbsp;&nbsp;&nbsp;<a title='删除'  href = 'Admin_DevMan_List.aspx?num=" + reader[0].ToString() + "'><i class='layui-icon'>&#xe640;</i></td></tr>";

                        //trd += "<td><a title = '查看详细信息' href = 'Admin_DevMan_Details.aspx?id=" + reader[0].ToString() + "'><i class='layui-icon'>&#xe60b;</i></a></td><td><a title='删除' onclick='delete_confirm();' href='javascript:;' id='adel'><i class='layui-icon'>&#xe640;</i></td></tr>";
                        k = k + 1;
                    }
                    //Response.Write(tabelall + trd + "</tbody></table>");

                    Label1.Text = tabelall + trd + "</tbody></table>";
                    MsgNum.Text = k.ToString();

                }
            }

        }

        finally
        {
            conn.Close();
        }
    }

    //protected void Del_Click(object sender, EventArgs e)
    //{
    //    string pronum = HiddenField1.Value + "11";
    //    Response.Write(pronum);
    //    SqlConnection conn = new SqlConnection();
    //    conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringProManage"].ConnectionString;
    //    try
    //    {
    //        conn.Open();

    //        //删除记录
           

    //    }
    //    finally
    //    {
    //        conn.Close();
    //    }

    //}
}